package com.example.mapper;

import com.example.pojo.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeptMapper {
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time")
    })
    @Select("SELECT id,name,create_time,update_time FROM dept order by update_time DESC;")
    List<Dept> findAll();
    @Insert("INSERT INTO dept(name,create_time,update_time) VALUES(#{name},#{createTime},#{updateTime});")
    void add(Dept dept);
    /**
     * 通过id查询部门
     * @param id 部门id
     * @return 部门对象
     */
    @Select("SELECT id,name,create_time,update_time FROM dept WHERE id=#{id};")
    Dept findById(Integer id);

    /**
     * 修改部门
     * @param dept 部门对象
     */
    @Update("UPDATE dept SET name=#{name},update_time=#{updateTime} WHERE id=#{id};")
    void update(Dept dept);
    /**
     * 删除部门
     * @param id 部门id
     */
    @Delete("DELETE FROM dept WHERE id=#{id};")
    void delete(Integer id);

}
